home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / MacTCPToolBx / Source Code ƒ / Rot13.p < prev    next >
Text File  |  1989-06-01  |  2KB  |  76 lines

  1. (*
  2.     Rot13(string) -- Return the string transformed by Rot13 (for every letter in the string (as opposed to
  3.         number or special character), circularly rotate it through the letters of the alphabet 13 placed).
  4.  
  5.     To compile and link this file using Macintosh Programmer's Workshop,
  6.  
  7.         pascal -w Rot13.p
  8.         link -m ENTRYPOINT -o HyperCommands -rt XFCN=7868 -sn Main=Rot13 ∂
  9.             Rot13.p.o "{Libraries}HyperXLib.o" "{MPW}"Libraries:interface.o
  10.  
  11.     © Copyright 1989 by Apple Computer, Inc.
  12.  
  13.     Initial coding 2/15/89 by Harry R. Chesley.
  14. *)
  15.  
  16. {$R-}
  17.  
  18. {$S Rot13 }     { Segment name must be the same as the command name. }
  19.  
  20. unit DummyUnit;
  21.  
  22. interface
  23.  
  24. uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
  25.  
  26. procedure EntryPoint(paramPtr: XCmdPtr);
  27.     
  28. implementation
  29.  
  30. procedure Rot13(paramPtr: XCmdPtr); forward;
  31.  
  32. procedure EntryPoint(paramPtr: XCmdPtr);
  33.  
  34.     begin
  35.         Rot13(paramPtr);
  36.     end;
  37.  
  38. procedure Rot13(paramPtr: XCmdPtr);
  39.  
  40.     var resultHand: Handle;
  41.         p: Ptr;
  42.         theChar: char;
  43.  
  44.     procedure Fail(errMsg: Str255); { set theResult and quit }
  45.         begin
  46.             paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
  47.             exit(Rot13);
  48.         end;
  49.  
  50.     begin
  51.         if paramPtr^.paramCount <> 1 then Fail('§§§ parameter count is not 1 §§§');
  52.  
  53.         resultHand := paramPtr^.params[1];                { First parameter is the string to be rotated. }
  54.  
  55.         { If there's anything in the "previous" string, copy it. }
  56.         if resultHand <> NIL then
  57.             begin
  58.                 if HandToHand(resultHand) <> noErr then Fail('§§§ HandToHand failed §§§');
  59.                 { Cycle through the text. }
  60.                 p := resultHand^;
  61.                 while p^ <> 0 do
  62.                     begin
  63.                         theChar := chr(p^);
  64.                         { If this char is rotable, rot it... }
  65.                         if theChar in ['A'..'M','a'..'m'] then p^ := p^ + 13
  66.                         else if theChar in ['N'..'Z','n'..'z'] then p^ := p^ - 13;
  67.                         p := Ptr(ord4(p)+1);
  68.                     end;
  69.             end;
  70.  
  71.         { Return the handle. }
  72.         paramPtr^.returnValue := resultHand;
  73.     end;
  74.  
  75. end.
  76.